package test06.stream.demo02.t09;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author ZQX
 * @date 2025-04-08
 */
public class MainTest06 {
    public static void main(String[] args) {
        // 第一：定义数据源，并获取对应的流对象
        Student s1 = new Student("张三","男",18,55) ;
        Student s2 = new Student("李四","女",28,63) ;
        Student s3 = new Student("王五","男",38,50) ;
        Student s4 = new Student("赵六","女",48,99) ;
        List<Student> list = Arrays.asList(s1,s2,s3,s4);

        // 第二：操作 - 拼接操作
        // 1.无参:join()
        String str1 = list.stream()
                .map(s -> s.getName())
                .collect(Collectors.joining());
        System.out.println(str1);

        // 2.一个参数:joining(CharSequence delimiter)
        String str2 = list.stream()
                .map(s -> s.getName())
                .collect(Collectors.joining(","));
        System.out.println(str2);

        // 3.三个参数:joining(CharSequence delimiter, CharSequence prefix,CharSequence suffix)
        String str3 = list.stream()
                .map(s -> s.getName())
                .collect(Collectors
                        .joining(",","[","]"));
        System.out.println(str3);

    }
}
